package com.cskaoyan.day4._04_vector;

import java.util.concurrent.TimeUnit;

/**
 * @author Common-zhou
 * @since 2023-03-02 11:41
 */
public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        User user = new User();

        for (int i = 0; i < 5; i++) {
            new Thread(
                new CountRunnable(user)
            ).start();
        }

        TimeUnit.SECONDS.sleep(5);
        System.out.println(user.count);


    }
}

class User {
    int count = 0;
}

class CountRunnable implements Runnable {

    User user;

    public CountRunnable(User user) {
        this.user = user;
    }

    @Override
    public void run() {
        for (int i = 0; i < 10000; i++) {
            this.user.count++;
        }
    }
}
